#!/bin/sh
##########		name:Zdir容器运行入口			##########
##########		update:2020/06/21				##########
##########		author:xiaoz<xiaoz93@outlook.com>	######

zdir_path='/data'
zdir_url='https://gitee.com/fenei/zdir/repository/archive/v1.55?format=tar.gz'
#安装Zdir
function install_zdir(){
	#如果zdir/index.php不存在，则下载Zdir
	if [ ! -f "${zdir_path}/index.php" ]
	then
		echo '-------------------------------------------'
		#创建目录
		mkdir -p $zdir_path
		rm -rf /data/wwwroot
		#下载源码
		wget -O ${zdir_path}/zdir.tar.gz ${zdir_url}
		#进入目录
		cd $zdir_path
		tar -zxvf zdir.tar.gz
		#重命名配置文件
		#mv ${zdir_path}/zdir.tar.gz ../
		cp ${zdir_path}/zdir/config.simple.php ${zdir_path}/zdir/config.php
		#设置读取的路径
		sed -i "s%\"thedir.*%\"thedir\"=>'/data',%g" ${zdir_path}/zdir/config.php
		echo '-------------------------------------------'
		
		#设置用户组权限
		chown -R www:www $zdir_path
		rm -rf zdir.zip
	fi
	
}
#install Zdir
install_zdir
#set permission
chown -R www:www /data/
chown -R www:www /var/lib/nginx/
#start php-fpm
php-fpm7 -D
#start nginx
/usr/sbin/nginx
tail -f /var/log/nginx/error.log
